package Segments;

import event.Event;
/*
 * Falta hacer que el SymbolTable ordene los eventos para sacar el evento
 * que se encuentre en el head, o el SQS.
 */
public class FEL implements java.io.Serializable{
	private Node SQS ;
	//private final static Node SQS;
   	/*static {
        SQS  = new Node(0,new Event());
        SQS.next = SQS;
        SQS.prev = SQS;
    }*/

	private class Node{
		double key;
		Event value;
		Node next;
		Node prev;
		Node left;
		Node right;
		Node(double key, Event value, Node next, Node prev){
			this.key = key;
			this.value =value;
			this.next = next;
			this.prev = prev;
			
		}
		Node(double key,Event value){
			this.key = key;
			this.value = value;
		}
		public String toString(){
			return ("Time:"+value.evTime());
		}
		
	}
	public void put(Event val){ //podemos colar eventos como objetos, y el string seria la hora.
		if(SQS == null){
			SQS = new Node(0,new Event(){
				public   Object objectId(){
					return 0;
				}
				 public  double evTime(){
					 return 0;
				 }
				    public  double evPosition(){
				    	return 0;
				    }
				    public  int evType(){
				    	return 0;
				    }
				    public void run(){
				    	
				    }
			});
			SQS.next = SQS;
			SQS.prev = SQS;
		}
		Node x = SQS;
				while(val.evTime()<x.next.value.evTime()&& x.next != SQS)
					x = x.next;
				
				x.prev = (new Node(val.evTime(),val,x,x.prev));
				x.prev.prev.next = x.prev;
				
			
		
		for(x = SQS.next;x!=SQS;x = x.next){
			System.out.println(x);
		}
	}
	public Event get (double k){
		for(Node x = SQS;x != SQS;x =x.next)
			if(k == x.value.evTime()) return x.value; //exhaustively search for key
		return null; //not found
	}
	public Event getEvent(){
		Node x = SQS.next;
		return x.value;
	}
	public Node getRootNode(){
		return SQS;
	}
}
